import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_hall/utils.dart';

class MapPage extends StatefulWidget {
  final String line;
  final int lineIndex;

  const MapPage({Key? key, required this.line, required this.lineIndex})
      : super(key: key);

  @override
  State<MapPage> createState() => _MapListState();
}

class _MapListState extends State<MapPage> {
  final controller = ScrollController();
  List list = [];

  @override
  void initState() {
    super.initState();
    Utils.getTracks().then((value) => {
          setState(() {
            list = value[widget.lineIndex]['polylines'];
          })
        });
  }

  List<Widget> _listItem() {
    List<Widget> _lists = <Widget>[];
    for (var e in list) {
      _lists.add(
        GestureDetector(
            onTap: () {
              Navigator.pop(context, e['title']);
            },
            child: Container(
              decoration: BoxDecoration(
                  boxShadow: const [
                    BoxShadow(
                        color: Colors.grey,
                        blurRadius: 10.0,
                        offset: Offset(3, 3)),
                  ],
                  color: Colors.white,
                  borderRadius: BorderRadius.circular((12.0))),
              margin: const EdgeInsets.only(bottom: 20, left: 12, right: 12),
              child: Flex(
                crossAxisAlignment: CrossAxisAlignment.start,
                direction: Axis.vertical,
                children: [
                  Container(
                    color: Colors.black54,
                    width: MediaQuery.of(context).size.width,
                    padding: const EdgeInsets.fromLTRB(8, 4, 4, 4),
                    child: Text(
                      e['title'],
                      style: const TextStyle(fontSize: 16,color: Colors.white),
                    ),
                  ),
                  const SizedBox(
                    height: 9,
                  ),
                  Container(
                    width: MediaQuery.of(context).size.width,
                    padding: const EdgeInsets.fromLTRB(10, 4, 4, 10),
                    child: Text(
                      e['desc'],
                      style: const TextStyle(fontSize: 12),
                    ),
                  ),
                ],
              ),
            )),
      );
    }
    return _lists;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(widget.line, style: const TextStyle(color: Colors.black)),
          systemOverlayStyle: const SystemUiOverlayStyle(
              systemNavigationBarColor: Colors.black,
              systemNavigationBarDividerColor: null,
              statusBarColor: null,
              systemNavigationBarIconBrightness: Brightness.light,
              statusBarIconBrightness: Brightness.dark,
              statusBarBrightness: Brightness.light),
          elevation: 0.3,
          backgroundColor: Colors.white,
          iconTheme: const IconThemeData(color: Colors.black, opacity: 0.8),
        ),
        backgroundColor: Colors.white,
        body: Container(
          padding: const EdgeInsets.only(top: 20),
          child: ListView(
            children: _listItem(),
          ),
        ));
  }
}
